Fix sub-pixel jitter after tile separation#7253
Fix sub-pixel jitter after tile separation#7253danitpeck wants to merge 1 commit intophaserjs:masterfrom
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Free Tier Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable autofix in the Cursor dashboard.
1773d0c to
d01636b
Compare
|
Good catch, snapping to the nearest can change the resolved position and cause overlap. I'll revisit and either make the snap direction-aware or avoid mutating the physics position directly |
|
Also worth adding this is likely solved via all the work we did around pixel art rendering in v4 (see https://github.com/phaserjs/phaser/blob/v4.0.0/docs/Phaser%204%20Pixel%20Art%20Guide/Phaser%204%20Pixel%20Art%20Guide.md) |
|
I've reviewed the test case in Phaser v4, and it looks like we no longer get flickering of this sort. Pixel art rendering got some upgrades which handle things more generally. We do get visual penetration, but I think that's intentional in this case, as the body is 14px tall on a 16px sprite. I'm going to close this as no longer relevant to ongoing development of v4. But if you find floats floating buzzily in other situations - which they might, and you're clearly handling this stuff frequently - please file a new issue! |

This PR:
Describe the changes below:
Fixes #7252
ProcessTileSeparationX/Y can leave body.position at fractional values after subtracting the overlap, like 63.9997 instead of 64.
Tiles are at whole pixel coords so this shouldn't happen, but float math is gonna float math. In pixelArt games it shows up as sprites jittering 1px back and forth while just standing on a tile.
The fix: after the subtraction, if the result is within 0.01 of a whole number, snap it. Catches the float drift without messing up bodies that are supposed to be fractional (scaled sprites with non-integer dimensions, etc).
Note
Low Risk
Small, localized change to tile collision resolution; main risk is edge-case behavior changes for bodies that rely on tiny fractional positions near pixel boundaries.
Overview
Fixes sub-pixel jitter after Arcade Physics tile separation by snapping
body.position.x/yto the nearest integer when the post-separation value is very close to a whole pixel.The new rounding is tolerance-based (
< 0.01) so intentionally fractional positions (e.g., from scaled sprites / non-integer body sizes) are preserved, and the rest of the separation/bounce logic remains unchanged.Written by Cursor Bugbot for commit d01636b. This will update automatically on new commits. Configure here.